package com.play.ballen.splash

import com.play.ballen.utils.UserInfoManager
import com.yuven.appframework.busevent.SingleLiveEvent
import com.yuven.appframework.network.RxSchedulerHelper
import com.yuven.appframework.util.addToDisposable
import com.yuven.baselib.component.viewmodel.BaseViewModel
import com.yuven.baselib.utils.Logger
import io.reactivex.Observable

class SplashVM : BaseViewModel() {

    val actionReadUserComplete = SingleLiveEvent<Void>()

    fun readUserInfoFromMMKV() {
        Observable.just(1)
            .map {
                UserInfoManager.readUserInfoFromMMKV()
            }
            .compose(RxSchedulerHelper.io_main())
            .doFinally {
                actionReadUserComplete.call()
            }
            .subscribe({
                Logger.i("SplashVM.readUserInfoFromMMKV success")
            }, { throwable ->
                Logger.i("SplashVM.readUserInfoFromMMKV error,msg = ${throwable.message}")
            }).addToDisposable(compositeDisposable)
    }

}